package com.sc.mapper;

import java.io.IOException;
import java.util.List;

import org.ansj.domain.Result;
import org.ansj.domain.Term;
import org.ansj.splitWord.analysis.ToAnalysis;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

/**
 * 
 * @Description TODO
 * @author pengjun
 * @version v1.0
 * @date 2020年7月9日
 * 
 */
public class ZHWordCountMapper extends Mapper<LongWritable, Text, Text, LongWritable> {

	LongWritable longWritable = new LongWritable();
	Text text = new Text();
	
	@Override
	protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, Text, LongWritable>.Context context)
			throws IOException, InterruptedException {
		// TODO Auto-generated method stub
		String line = value.toString().trim();
		if (line != null && !line.equals("")) {
			Result parse = ToAnalysis.parse(line);
			List<Term> terms = parse.getTerms();
//			Iterator<Term> iterator = terms.iterator();
			for (Term term : terms) {
				longWritable.set(1);
				text.set(term.getName());
				context.write(text, longWritable);
			}
		}
	}
}
